﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HiStaff.Util;
using HiStaff.Base;
using HiStaff.Control;
using HiStaff.Dal;
using HiStaff.Domain.CO;
namespace HiStaff.iTime
{
    public partial class SwipeDataRegister : BaseRegister
    {
        private const string MSG_INVALID_DATE = "Ngày kết thức không được nhỏ hơn ngày bắt đầu.";
        private const string MSG_INVALID_PERIOD = "Kỳ công đã đóng, không thể thực hiện việc đăng ký.";
        //private frmFilterEmployee frmChooseEmp = new frmFilterEmployee();

        //public DateTime FromDate
        //{
        //    get
        //    {
        //        return cldFromDate.Value;
        //    }
        //}

        //public DateTime ToDate
        //{
        //    get
        //    {
        //       return cldToDate.Value;
        //    }
        //}   

        public SwipeDataRegister()
        {
            InitializeComponent();
        }

        private void frmSwipeDataRegister_Load(object sender, EventArgs e)
        {
            try
            {
                AddForcusControl = mcbxEmployee;
                EditForcusControl = mcbxEmployee;
                SaveForcusControl = mcbxEmployee;
                CancelForcusControl = mcbxEmployee;
                DeleteForcusControl = mcbxEmployee;

                base.CreateCommandBar(CommandBarManager.ActionCommand.New,
                                      CommandBarManager.ActionCommand.Separator,
                                      CommandBarManager.ActionCommand.Save,
                                      CommandBarManager.ActionCommand.Cancel,
                                      CommandBarManager.ActionCommand.Separator,
                                      CommandBarManager.ActionCommand.Exit);
               //ChooseEmp.Username = StaticObject.Username;
               //ChooseEmp.EmployeeSelection = ListEmployeeRegist;

                ClearForm();

                InitForm();

                SetStatusInputControl(this, true);
                SetToolStripButtonBar(CommandBarManager.ActionCommand.New);

                if (ListEmployeeRegist == null || ListEmployeeRegist.Count == 0)
                {
                    //jbtnSearchEmp.PerformClick();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "/r/n" + ex.StackTrace);
                Log.Instance.WriteExceptionLog(ex, this.Name + "[" + this.Text + "]");
            }
        }

        private void InitForm()
        {
            mcbxEmployee.DisplayMember = "MULTIDISPLAYNAME";
            mcbxEmployee.ValueMember = "EMPLOYEEID";
            //mcbxEmployee.SetDataBinding(frmChooseEmp.EmployeeSelection, "EMPLOYEEID");

            cldFromDate.Value = DateTime.Now;
            cldToDate.Value = DateTime.Now;
        }

        protected override void SetStatusInputControl(System.Windows.Forms.Control container, bool status)
        {
            grbMainBase.Enabled = status;
        }

        private void jbtnSearchEmp_Click(object sender, EventArgs e)
        {
            //frmChooseEmp.ShowDialog();
            //if (frmChooseEmp.EmployeeSelection.Count > 0)
            //{
            //    mcbxEmployee.DataSource = null;
            //    mcbxEmployee.SetDataBinding(frmChooseEmp.EmployeeSelection, "EMPLOYEEID");
            //    mcbxEmployee.SelectedIndex = 0;
            //}
            //else
            //{
            //    mcbxEmployee.SelectedIndex = -1;
            //    mcbxEmployee.DataSource = null;
            //}
        }

        protected void ClearForm()
        {
            cldFromDate.Value = DateTime.Now;
            cldToDate.Value = DateTime.Now;

           // jbtnSearchEmp.Focus();
        }

        protected override bool AddNewButtonClick()
        {
            return true;
        }

        protected override bool CancelButtonClick()
        {
            ClearForm();

            return true;
        }

        //protected override bool SaveButtonClick()
        //{
        //    CO_SWIPE_DATA objUpdate;
            //DateTime workingdate;

            //if (!ValidateData())
            //{
            //    return false;
            //}

            //foreach (var item in frmChooseEmp.EmployeeSelection)
            //{
            //    workingdate = cldFromDate.Value;
            //    while (workingdate <= cldToDate.Value)
            //    {
            //        objUpdate = new CO_SWIPE_DATA();
            //        objUpdate.EMPLOYEEID = item.EMPLOYEEID;
            //        objUpdate.WORKINGDAY = workingdate;
            //        objUpdate.Username = StaticObject.Username;

            //        OracleHelper.ExcuteNonQuery(PKG_HCM_COLEX.NAME, PKG_HCM_COLEX.PRU_INOUTVAL, objUpdate);

            //        workingdate = workingdate.AddDays(1);
            //    }
            //}

            //MessageBox.Show(Constant.MSG_RGT_SUCCESS, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            //ClearForm();

            //this.RegisterResult = DialogResult.OK;

            //this.Close();

        //    return true;
        //}

        //private bool ValidateData()
        //{
        //    if (cldFromDate.Value > cldToDate.Value)
        //    {
        //        MessageBox.Show(MSG_INVALID_DATE, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //        return false;
        //    }

        //    if (frmChooseEmp.EmployeeSelection.Count == 0)
        //    {
        //        MessageBox.Show(Constant.MSG_INVALID_EMPCOUNT, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //        return false;
        //    }

        //    CO_SUM_SEARCH objSearch;
        //    //check period status
        //    foreach (var item in frmChooseEmp.EmployeeSelection)
        //    {
        //        objSearch = new CO_SUM_SEARCH();
        //        objSearch.EMPLOYEEID = item.EMPLOYEEID;
        //        objSearch.STARTDATE = cldFromDate.Value;
        //        objSearch.ENDDATE = cldToDate.Value;
        //        OracleHelper.ExcuteNonQuery(PKG_HCM_COLEX.NAME, PKG_HCM_COLEX.PRS_CHKCOLEXRGT, objSearch);

        //        if (objSearch.CLOSEPERIOD > 0)
        //        {
        //            MessageBox.Show(MSG_INVALID_PERIOD, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        //            return false;
        //        }
        //    }

        //    return true;
        //}
    }
}
